package com.itheima.controller;

import com.itheima.model.Item;
import com.itheima.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：shenkunlin
 * @date： 2021/7/5 11:49
 * @Description：
 ***/
@RestController
@RequestMapping(value = "/item")
//@RefreshScope
public class ItemController {

    //获取端口
    @Value("${server.port}")
    private Integer port;

    @Autowired
    private ItemService itemService;

    //@Value("${city:深圳}")
    //private String city;

    @Autowired
    private Environment env;

    /**
     * 获取城市
     * @return
     */
    @GetMapping(value = "/city")
    public String getCity(){
        return env.getProperty("city");
    }

    /**
     * 修改库存，并返回单价
     */
    @GetMapping(value = "/{id}/{count}")
    public int decrCount(@PathVariable(value = "id")Integer id,
                         @PathVariable(value = "count")Integer count){
        System.out.println("当前服务端口->"+port);
        return itemService.decrCount(id,count);
    }

    /***
     * 根据ID查询商品详情
     */
    @GetMapping(value = "/one/{id}")
    public Item one(@PathVariable(value = "id")Integer id){
        return itemService.one(id);
    }
}
